package com.sizu.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sizu.common.dto.PurchaseListGoodsDto;
import com.sizu.common.dto.ReturnListGoodsDto;
import com.sizu.common.vo.ResultEntity;
import com.sizu.entity.TPurchaseListGoods;
import com.sizu.entity.TReturnListGoods;
import com.sizu.service.impl.TReturnListGoodsServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-02-21
 */
@RestController
@RequestMapping("/purchase/tReturnListGoods")
public class TReturnListGoodsController {

    @Autowired
    private TReturnListGoodsServiceImpl tReturnListGoodsServiceImpl;

    //根据退货id查询出所有的商品
    @RequestMapping("/goodsList")
    public ResultEntity goodsList(Integer id){
        Wrapper<TReturnListGoods> wrapper = new EntityWrapper<TReturnListGoods>();
        wrapper.eq("return_list_id",id);
        List<TReturnListGoods> tReturnListGoods = tReturnListGoodsServiceImpl.selectList(wrapper);
        return ResultEntity.ok(tReturnListGoods);
    }

    //做删除的方法
    @RequestMapping("/deletereturnListGoods")
    public ResultEntity deletetPurchaseListGoods(ReturnListGoodsDto returnListGoodsDto){
        TReturnListGoods tReturnListGoods = new TReturnListGoods();
        BeanUtils.copyProperties(returnListGoodsDto,tReturnListGoods);
        Wrapper<TReturnListGoods> wrapper = new EntityWrapper<TReturnListGoods>();
        wrapper.eq("code",returnListGoodsDto.getCode());
        boolean delete = tReturnListGoodsServiceImpl.delete(wrapper);
        if(delete==true){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
        return ResultEntity.ok();
    }


    //做添加的方法
    @RequestMapping("/updatetreturnListGoods")
    public ResultEntity updatetPurchaseListGoods(ReturnListGoodsDto returnListGoodsDto){
        TReturnListGoods tReturnListGoods = new TReturnListGoods();
        BeanUtils.copyProperties(returnListGoodsDto,tReturnListGoods);
        Wrapper<TReturnListGoods> wrapper = new EntityWrapper<TReturnListGoods>();
        wrapper.eq("code",returnListGoodsDto.getCode());
        TReturnListGoods tReturnListGoods1 = tReturnListGoodsServiceImpl.selectOne(wrapper);
        if(null!=tReturnListGoods1){
            tReturnListGoodsServiceImpl.updateById(tReturnListGoods);
        }
        return ResultEntity.ok();
    }
}
